home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch2 / Stopwatch2 / Control.C next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.5 KB  |  90 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ////////////////////////////////////////////////////////////////////
  22. // Control.C: A start/stop pair of buttons for the stopwatch program
  23. /////////////////////////////////////////////////////////////////////
  24. #include "Control.h"
  25. #include <Xm/Xm.h>
  26. #include <Xm/RowColumn.h>
  27. #include <Xm/PushB.h>
  28. #include "Timer.h"
  29. #include "Stopwatch.h"
  30.  
  31. Control::Control ( Widget     parent, 
  32.           char      *name, 
  33.           Stopwatch *stopwatch,
  34.           Timer     *timer ) :  BasicComponent ( name )
  35. {
  36.     
  37.     _timer     = timer;     // Keep a pointer to the timer.
  38.     _stopwatch = stopwatch; // Remember stopwatch
  39.     
  40.     // Create the component's widget tree
  41.     
  42.     _w = XmCreateRowColumn ( parent, _name, NULL, 0 );
  43.     
  44.     _startWidget = XtCreateManagedWidget ( "start",
  45.                       xmPushButtonWidgetClass, 
  46.                       _w,  NULL, 0 );
  47.     _stopWidget = XtCreateManagedWidget ( "stop", 
  48.                      xmPushButtonWidgetClass, 
  49.                      _w, NULL, 0 );
  50.     
  51.     // Register callbacks, specifying the object's instance 
  52.     // pointer as client data.
  53.     
  54.     XtAddCallback ( _startWidget, 
  55.            XmNactivateCallback, 
  56.            &Control::startCallback,
  57.            (XtPointer) this );
  58.     
  59.     XtAddCallback ( _stopWidget, 
  60.            XmNactivateCallback, 
  61.            &Control::stopCallback,
  62.            (XtPointer) this );
  63. }
  64.  
  65. void Control::startCallback ( Widget, XtPointer clientData, XtPointer )
  66. {
  67.     Control *obj = (Control *) clientData;
  68.     
  69.     obj->start();
  70. }
  71.  
  72. void Control::start()
  73. {
  74.     _timer->start();
  75.     _stopwatch->timerStarted();
  76. }
  77.  
  78. void Control::stopCallback ( Widget, XtPointer clientData, XtPointer )
  79. {    
  80.     Control *obj = (Control *) clientData;
  81.     
  82.     obj->stop();
  83. }
  84.  
  85. void Control::stop()
  86. {
  87.     _timer->stop();
  88.     _stopwatch->timerStopped();
  89. }
  90.